package com.xydtech.ecard.ecard.service.impl;

import com.xydtech.ecard.ecard.domain.EcardApiVisitRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xydtech.ecard.ecard.mapper.EcardAccessRecordListMapper;
import com.xydtech.ecard.ecard.domain.EcardApiAccessRecordList;
import com.xydtech.ecard.ecard.service.IEcardAccessRecordListService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 电子名片浏览记录明细Service业务层处理
 * 
 * @author Daniel
 * @date 2021-09-14
 */
@Service
public class EcardAccessRecordListServiceImpl implements IEcardAccessRecordListService 
{
    @Autowired
    private EcardAccessRecordListMapper ecardAccessRecordListMapper;

    /**
     * 新增电子名片访问记录
     * @param ecardAccessRecordList
     * @return
     */
    @Override
    public int insertEcardAccessRecordList(EcardApiAccessRecordList ecardAccessRecordList){
        return ecardAccessRecordListMapper.insertEcardAccessRecordList(ecardAccessRecordList);
    }

    /**
     * 电子名片-电子名片-获取电子名片的访问记录
     * @param userId
     * @return
     */
    @Override
    public List<EcardApiVisitRecord> getEcardAccessRecordList(String userId){
        return ecardAccessRecordListMapper.getEcardAccessRecordList(userId);
    }

    /**
     * 电子名片-电子名片-获取电子名片访问的汇总数据
     * @param currentUserId
     * @return
     */
    @Override
    public Map<String, Object> getEcardAccessRecordTotalData(String currentUserId) {
        Map<String,Object> map = new HashMap<>();

        //获取电子名片访问的总次数
        Integer visitTotalCount = ecardAccessRecordListMapper.getEcardAccessRecordTotalCount(currentUserId);
        map.put("visitTotalCount", visitTotalCount);

        //获取排行榜
        List<String> visitCountSortList =  ecardAccessRecordListMapper.getVisitCountSortList();
        int sortIndex = visitCountSortList.indexOf(currentUserId);
        map.put("sortIndex", sortIndex+1);

        return map;
    }
}
